package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DeskQuestion;
import com.ruoyi.system.service.IDeskQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问题Controller
 * 
 * @author ruoyi
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/system/question")
public class DeskQuestionController extends BaseController
{
    @Autowired
    private IDeskQuestionService deskQuestionService;

    /**
     * 查询问题列表
     */
    @PreAuthorize("@ss.hasPermi('system:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeskQuestion deskQuestion)
    {
        startPage();
        List<DeskQuestion> list = deskQuestionService.selectDeskQuestionList(deskQuestion);
        return getDataTable(list);
    }

    /**
     * 导出问题列表
     */
    @PreAuthorize("@ss.hasPermi('system:question:export')")
    @Log(title = "问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeskQuestion deskQuestion)
    {
        List<DeskQuestion> list = deskQuestionService.selectDeskQuestionList(deskQuestion);
        ExcelUtil<DeskQuestion> util = new ExcelUtil<DeskQuestion>(DeskQuestion.class);
        util.exportExcel(response, list, "问题数据");
    }

    /**
     * 获取问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deskQuestionService.selectDeskQuestionById(id));
    }

    /**
     * 新增问题
     */
    @PreAuthorize("@ss.hasPermi('system:question:add')")
    @Log(title = "问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeskQuestion deskQuestion)
    {
        return toAjax(deskQuestionService.insertDeskQuestion(deskQuestion));
    }

    /**
     * 修改问题
     */
    @PreAuthorize("@ss.hasPermi('system:question:edit')")
    @Log(title = "问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeskQuestion deskQuestion)
    {
        return toAjax(deskQuestionService.updateDeskQuestion(deskQuestion));
    }

    /**
     * 删除问题
     */
    @PreAuthorize("@ss.hasPermi('system:question:remove')")
    @Log(title = "问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deskQuestionService.deleteDeskQuestionByIds(ids));
    }
}
